<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('系统管理员操作界面')"/>
    <!--<th:block th:include="include :: bootstrap-select-css"/>-->
    <!--<th:block th:include="include :: jasny-bootstrap-css"/>-->
    <!--<th:block th:include="include :: datetimepicker-css"/>-->
    <link th:href="@{/ruoyi/css/font-awesome.css}" rel="stylesheet"/>
    <link th:href="@{/ruoyi/css/jquery-confirm.min.css}" rel="stylesheet"/>
</head>
<style type="text/css">

    @media screen and (max-width: 768px) {

    }

    /**电脑屏幕下显示***/
    @media screen and (min-width: 768px) {
        body {
            /*text-align:center;*/
            margin: 0px auto;
        }
        .dawenh{
            margin-left: -20px;width: 110%;
        }
        .qbinput{
            margin-left: -20px;width: 73%;float: right;
        }
    }
</style>
<body class="gray-bg">
<!--添加档案文号开始-->
<div class="modal fade" id="tjgzflModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     data-backdrop="static" data-keyboard="false">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="tjModalLabel">添加档案文号</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal">
                    <div class="form-group">
                        <label class="col-sm-4">故障分类</label>
                        <div class="col-sm-8">
                            <input type="text" name="gzfl" class="form-control" id="tj_gzfl"
                                   placeholder="请输入添加部门名称">
                            <span class="help-block"></span>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="tj_jjfa_btn">添加</button>
            </div>
        </div>
    </div>
</div>
<!--添加档案文号结束-->
<!--编辑模态框开始-->
<div class="modal fade" id="sbUpdateModal" tabindex="-1" role="dialog" aria-hidden="true"
     data-keyboard="false">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span>
                </button>
                <h1 class="modal-title"><strong>维护档案文号</strong></h1>
            </div>
            <div class="modal-body">
                <form id="form-sb-update" class="form-horizontal">
                    <div class="row" style="display: none">
                        <div class="form-group">
                            <label class="col-sm-4 control-label">公司编码</label>
                            <div class="col-sm-8">
                                <input name="gsid" id="gsid_up" class="form-control" type="text" required="required">
                                <input id="gsid_yc" class="form-control" type="text">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-sm-4 control-label">文号名称</label>
                            <div class="col-sm-8">
                                <div class="input-group dawenh">
                                    <input name="whmc" id="gzfl_up" class="form-control" type="text" required="required">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-sm-4 control-label">档案文号</label>
                            <div class="col-sm-8">
                                <div class="input-group dawenh">
                                    <input name="wenh" id="gzyy_up" class="form-control" type="text" required="required">
                                    <input name="id" id="id_up" class="form-control" type="hidden">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <div class="modal-footer">
                                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                                <button type="button" class="btn btn-white" id="sb_update_btn" onclick="updatesb()">更新
                                </button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!--编辑模态框结束-->
<!--添加模态框开始-->
<div class="modal fade" id="sbAddModal" tabindex="-1" role="dialog" aria-hidden="true"
     data-keyboard="false">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span>
                </button>
                <h1 class="modal-title"><strong>添加档案文号</strong></h1>
            </div>
            <div class="modal-body">
                <form id="form-sb-add" class="form-horizontal">
                    <div class="row">
                        <div class="form-group">
                            <label class="col-sm-4 control-label">公司编码</label>
                            <div class="col-sm-8">
                                <input name="gsid" id="gsid_add" class="form-control" type="hidden" placeholder="请输入公司ID编码"
                                       required="required">
                                <select class="form-control m-b dawenh" id="bmid_add">
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-sm-4 control-label">文号描述</label>
                            <div class="col-sm-8">
                                <select class="form-control m-b dawenh" name="miaos" id="jjfa_add">
                                    <option value="">请选择文号描述</option>
                                    <option value="计算机设备登记表">计算机设备登记表</option>
                                    <option value="计算机系统维护登记表">计算机系统维护登记表</option>
                                    <option value="计算机设施设备管理台帐">计算机设施设备管理台帐</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-sm-4 control-label">文号名称</label>
                            <div class="col-sm-8 qbinput">
                                <input name="whmc" id="add_gzfl" class="form-control" type="text" placeholder="例：计算机设备登记表"
                                       required="required">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-sm-4 control-label">档案文号</label>
                            <div class="col-sm-8 qbinput">
                                <input name="wenh" id="gzyy_add" class="form-control" type="text" placeholder="例：HWGA-QR-114-2017-01"
                                       required="required">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <div class="modal-footer">
                                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                                <button type="button" class="btn btn-white" id="sb_save_btn" onclick="savesb()">保存
                                </button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!--添加模态框结束-->
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="operlog-form">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>检索：</label><input type="text" name="sbbh" id="sbbh" placeholder="请输入设备编码进行查询"
                                                     onkeydown="if(event.keyCode==13){event.keyCode=0;event.returnValue=false;$.alert('请点击后面的搜索框','温馨提示');}"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" id="search_btn"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="addgsmc()">
                <i class="fa fa-pencil"></i> 维护分类
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div><input type="hidden" id="_pageNumber"></div>
<div><input type="hidden" id="_pageSize"></div>
<p id="pusername" style="display: none">[[${session.username}]]</p>
<p id="pgsid" style="display: none">[[${session.gsid}]]</p>
<th:block th:include="include :: footer"/>
<script th:src="@{/ruoyi/js/jquery-confirm.min.js}"></script>
<script th:inline="javascript">
    // var sessionname = [[${session.username}]]
    // var gsid = [[${session.gsid}]]
    $(document).ready(function () {
        // $("#dengmz").val(sessionname)
        // if (gsid == null) {
        //     alert("当前状态未登陆系统或浏览器中当前会话结束了，您需要重新登陆")
        //     window.location.href = "/login";
        // }
        // $("#gsids").val(gsid)
        initUserTable();

        function initUserTable() {
            $("#bootstrap-table").bootstrapTable({
                toolbar: '#toolbar',
                showToggle: true,//是否切换显示
                showColumns: true,//是否显示列，
                showColumnsToggleAll: true,
                // detailView: true,//和下面的属性成对设置，是否显示加号显示详细信息
                // detailFormatter: "detailFormatter",
                showExport: true,//是否导出
                // showPaginationSwitch: true,//切换是否分页显示
                showFooter: true,//是否显示页脚，主要用途是显示汇总的信息
                striped: false,//是否显示行间隔色
                paginationPreText: '上一页',
                paginationNextText: '下一页',
                queryParamsType: '',
                method: 'GET',
                uniqueId: "id",
                exportDataType: "basic", //basic', 'all', 'selected'.
                // exportTypes:['Excel'],  //导出文件类型
                pageNumber: 'form' ? 1 : parseInt($('#_pageNumber').val()),
                pagination: true,//是否分页
                sidePagination: 'server',//server:服务器端分页|client：前端分页
                pageSize: 'form' ? 10 : parseInt($('#_pageSize').val()),//单页记录数
                pageList: [10, 20, 30, 'ALL'],//可选择单页记录数
                showRefresh: true,//刷新按钮
                queryParams: queryParams,
                // onDblClickRow: function (row,index) {
                //     console.log(index[0])
                // },
                url: "/sbgl/wenhb/getwenhblist/",
                columns: [{
                    checkbox: true
                },
                    {
                        field: 'no',
                        title: '序号',
                        align: "center",
                        width: 60,
                        formatter: function (value, row, index) {
                            return index + 1;
                        }
                    },
                    {
                        field: 'gsid',
                        title: '公司编码'
                    },
                    {
                        field: 'whmc',
                        title: '文号名称'
                    },
                    {
                        field: 'wenh',
                        title: '档案文号'
                    },
                    {
                        field: 'miaos',
                        title: '文号描述'
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function (value, row, index) {
                            var id = index;
                            var result = "";
                            result += "<a href='javascript:;' class='btn btn-xs blue'  onclick=\"EditViewById('" + row + "','" + id + "')\" title='维护'><span class='glyphicon glyphicon-pencil'></span></a>";
                            result += "<a href='javascript:;' class='btn btn-xs blue'  onclick=\"DeleteById('" + row + "','" + id + "')\" title='删除'><span class='glyphicon glyphicon-trash'></span></a>";
                            return result;
                        }
                    }]
            })
        }})
    function queryParams(params) {
        var param = {
            limit: params.limit, // 页面大小
            offset: params.offset, // 页码
            nextPage: params.pageNumber,
            pageNumber: params.pageNumber,
            pageSize: params.pageSize,
            cxtj: $("#sbbh").val(),
            gsid: $("#pgsid").text(),
            // bfbs: $("#is_bf").val(),
        };
        return param;
    }

    //查询按钮事件
    $('#search_btn').click(function () {
        refresh()
    });

    function refresh() {
        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;
        //获取当前是第几页
        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;
        $("#_pageNumber").val(pageNumber);
        $("#_pageSize").val(pageSize);
        $('#bootstrap-table').bootstrapTable('refresh', {
            pageNumber: pageNumber,
            pageSize: pageSize,
        });
    }

    function addgsmc() {
        $("add_gzfl").val("")
        $("#gzyy_add").val("")
        var gsid=$("#pgsid").text()
        $("#gsid_add").val(gsid)
        $("#sbAddModal").modal({
            backdrop: "static"
        });
        $.ajax({
            url: '/sbgl/gsxxb/getgsxxb',
            type: 'get',
            async: false,
            success: function (result) {
                $("#bmid_add").empty();
                var options = "";   //字符串拼接
                $("#bmid_add").append('<option value="0">请选择公司名称</option>');
                for (var i in result) {  //遍历json数组
                    options += "<option value='" + result[i].gsid + "'>" + result[i].gs + "</option>"
                }
                $("#bmid_add").append(options);
            }
        })
        var gsid_add=$("#gsid_add").val()
        if (gsid_add==""){
            gsid_add=0
        }else {
            $("#bmid_add").val(gsid_add);
            $('#bmid_add').attr("disabled", "disabled").unbind("click")
            var gsid = $("#bmid_add").val()
            $("#gsid_add").val(gsid)
        }
    }

    function confirm(title,content,ele) {
        $.confirm({
            title: title,
            content: content,
            buttons: {
                确定: {
                    text: '确定',
                    btnClass: 'btn-blue',
                    action: function(){
                        $(ele).modal('hide');
                    }
                }
            }
        });
    }

    $("#bmid_add").change(function () {
        var gsid = $("#bmid_add option:selected").val()
        $.ajax({
            url: "/sbgl/whflb/getgzfl/" + gsid,
            type: 'GET',
            async: false,
            success: function (data) {
                $('#add_gzfl').empty();
                var options = "";   //字符串拼接
                $("#add_gzfl").append('<option value="">请选择故障分类</option>');
                for (var i in data) {  //遍历json数组
                    options += "<option value='" + data[i].gzfl + "'>" + data[i].gzfl + "</option>"
                    //     // "<input type='radio' class='roles' name='roles' id='"+data[i].wjdcs+"' value='"+data[i].wjdc+"'>"+data[i].wjdc+"&nbsp;&nbsp;"
                }
                $('#add_gzfl').append(options);
            }
        })
        $("#gsid_add").val(gsid)
    })

    function savesb() {
        var whmc=$("#add_gzfl").val()
        var wenh=$("#gzyy_add").val()
        var miaos=$("#jjfa_add").val()
        var gsid=$("#gsid_add").val()
        if (gsid==""){
            $.alert("请选择公司名称","温馨提示")
            return false
        }
        if (whmc.length<=3||wenh.length<=5){
            $.alert("文号名称或档案文号的长度过短","温馨提示")
            return false
        }
        var iswenhb = cfpd("/sbgl/wenhb/getwenhb/", gsid)
        if (iswenhb!=""){
            var wenhs=[]
            var whmcs = []
            var miaoss=[]
            for (var i in iswenhb) {
                wenhs.push(iswenhb[i].wenh)
                whmcs.push(iswenhb[i].whmc)
                miaoss.push(iswenhb[i].miaos)
            }
            if (miaoss.indexOf(miaos) >= 0) {
                $.alert("文号描述已存在", "温馨提示")
                return false;
            }
            $.confirm({
                title: '温馨提示',
                content: '确定添加吗？？？',
                buttons: {
                    确定: {
                        text: '确定',
                        btnClass: 'btn-blue',
                        action: function () {
                            return $.ajax({
                                url: '/sbgl/wenhb/insertfl',
                                method: 'POST',
                                data: $("#sbAddModal form").serialize()
                            }).done(function (response) {
                                $("#sbAddModal").modal('hide');
                                $.alert("添加成功","温馨提示")
                                refresh()
                            }).fail(function () {
                            });
                        }
                    },
                    取消: {
                        text: '取消',
                        btnClass: 'btn-red',
                        action: function () {
                        },
                    },
                },
            });
        }else {
        $.confirm({
            title: '温馨提示',
            content: '确定添加吗？？？',
            buttons: {
                确定: {
                    text: '确定',
                    btnClass: 'btn-blue',
                    action: function () {
                        return $.ajax({
                            url: '/sbgl/wenhb/insertfl',
                            method: 'POST',
                            data: $("#sbAddModal form").serialize()
                        }).done(function (response) {
                            $("#sbAddModal").modal('hide');
                            $.alert("添加成功","温馨提示")
                            refresh()
                        }).fail(function () {
                        });
                    }
                },
                取消: {
                    text: '取消',
                    btnClass: 'btn-red',
                    action: function () {
                    },
                },
            },
        });
        }
    }
    function EditViewById(row, index)  {
        var data = JSON.stringify($("#bootstrap-table").bootstrapTable('getData')); //获取全部数据
        var data_json = JSON.parse(data);
        $("#gsid_up").val(data_json[index].gsid);
        $("#gzfl_up").val(data_json[index].whmc);
        $("#gzyy_up").val(data_json[index].wenh);
        $("#id_up").val(data_json[index].id);
        $("#sbUpdateModal").modal({
            backdrop: "static"
        });
    }
    function updatesb() {
        var ids= $("#id_up").val();
        var whmc=$("#gzfl_up").val()
        var wenh=$("#gzyy_up").val()
        var miaos=$("#jjfa_up").val()
        var gsid=$("#gsid_up").val()
        if (whmc.length<=2||wenh.length<=5){
            $.alert("文号名称或档案文号的长度过短","温馨提示")
            return false
        }
        var iswenhb = cfpd("/sbgl/wenhb/getwenhb/", gsid)
            var wenhs=[]
            var whmcs = []
            var miaoss=[]
            for (var i in iswenhb) {
                wenhs.push(iswenhb[i].wenh)
                whmcs.push(iswenhb[i].whmc)
                miaoss.push(iswenhb[i].miaos)
            }
            if (miaoss.indexOf(miaos) >= 0&&wenhs.indexOf(wenh)>=0&&whmcs.indexOf(whmc)>=0) {
                $.alert("文号描述档案文号文号名称已存在", "温馨提示")
                return false;
            }
            $.confirm({
                title: '温馨提示',
                content: '确定更新吗？？？',
                buttons: {
                    确定: {
                        text: '确定',
                        btnClass: 'btn-blue',
                        action: function () {
                            return $.ajax({
                                url: '/sbgl/wenhb/updatebyid/'+ids,
                                method: 'PUT',
                                data: $("#sbUpdateModal form").serialize()
                            }).done(function (response) {
                                $("#sbUpdateModal").modal('hide');
                                $.alert("更新成功","温馨提示")
                                refresh()
                            }).fail(function () {
                            });
                        }
                    },
                    取消: {
                        text: '取消',
                        btnClass: 'btn-red',
                        action: function () {
                        },
                    },
                },
            });
    }

    function DeleteById(row,index) {
        var data = JSON.stringify($("#bootstrap-table").bootstrapTable('getData')); //获取全部数据
        var data_json = JSON.parse(data);
        var id=data_json[index].id;
        var shiyr=data_json[index].whmc;
        $.confirm({
            title: '档案文号删除',
            content: '您现在的操作是删除档案文号，您确定删除【'+shiyr+'】吗？',
            buttons: {
                确认: function () {
                    $.ajax({
                        url: "/sbgl/wenhb/remove/" + id,
                        type: 'POST',
                        success: function (result) {
                            if (result != null) {
                                refresh()
                                confirm("温馨提示","解决方案删除成功！！！")
                            }
                        }
                    });
                },
                取消: function () {
                }
            }
        });
    }
</script>
</body>
</html>